﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WMSSyncData.Model;
using WMSSyncData.Model.WMSModel;
using WMSSyncData.Utils;

namespace WMSSyncData.DAL.SqlDB
{
    public class WMS_T_IQCDAL : BaseSqlDBDAL<WMS_T_IQC>
    {
        public List<WMS_T_IQC> GetAllUpdate()
        {
            string sql = @"SELECT * FROM dbo.wms_T_IQC WHERE Status='0'";
            var dt = SqlDBHelper.GetDataSet(sql).Tables[0];
            var result = MakeTablePackage(dt);
            return result;

        }

        public DataTable GetUpdate()
        {
            string sql = @"SELECT * FROM dbo.wms_T_InStockRM WHERE Status='3'";
            var dt = SqlDBHelper.GetDataSet(sql).Tables[0];
            return dt;
        }

        public bool UpdateUploadStatus(DataTable  list)
        {

            var result = false;
 
            if (list!=null&&list.Rows.Count > 0)
            {
                var sqlWhere = "where BillNo in (";
                foreach (DataRow item in list.Rows)
                {
                    sqlWhere = sqlWhere + "'" + item["BillNo"] + "',";
                }
                sqlWhere = sqlWhere.TrimEnd(',');
                sqlWhere = sqlWhere + ")";
                var sql = "UPDATE  wms_T_InStockRM SET Status='4'" + sqlWhere+ ";update wms_T_IQC set Status='9'  " + sqlWhere + " and  Status='0';";
                var updateRes = SqlDBHelper.ExcuteSQL(sql);
                if (updateRes > 0)
                {
                    result = true;
                }
            }
            return result;

        }
    }
}
